#!/usr/bin/env python
# -*-coding:utf-8 -*-

import os.path
from os import chdir as cd
from codecs import open
from jiskolib import enviar, recibir
from toolbox import loadFile, ls
from tui import show_loop
from sys import platform

home = os.path.expanduser('~')
cd(home)
if '.pyskorc' not in ls():
	username = raw_input('Introduzca su nombre de usuario de Jisko:\n> ').strip()
	apikey = raw_input('Introduzca su clave API de Jisko:\n> ').strip()
	fsock = open('.pyskorc', 'w', 'utf-8')
	fsock.write("username=%s" % username)
	fsock.write('\n')
	fsock.write("apikey=%s" % apikey)
	fsock.write('\n')
	if platform in ['linux2']:
		fsock.write("color=%s" % 'True')
		for kv in [('clr_user', 'lgreen'),
		('clr_sep', 'yellow'),
		('clr_reply', 'skyish')]:
			fsock.write('\n')
			fsock.write("%s=%s" % kv)
	else:
		fsock.write("color=%s" % 'False')
	fsock.close()
else:
	cfg = loadFile('.pyskorc')
	for k, v in cfg.items():
		if v in ['False', 'false']:
			cfg[k] = False
	username = cfg['username']
	apikey = cfg['apikey']
	print "Logueado como '%s'" % username 
	#print apikey
	show_loop(username, apikey, cfg)
